package com.huike.web.controller.clues;

import java.util.Date;
import java.util.List;

import com.fasterxml.classmate.members.RawConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.TbClueTrackRecord;
import com.huike.clues.domain.vo.ClueTrackRecordVo;
import com.huike.clues.service.ITbClueTrackRecordService;
import com.huike.common.annotation.Log;
import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import com.huike.common.enums.BusinessType;
import com.huike.common.utils.DateUtils;
import com.huike.common.utils.SecurityUtils;

/**
 * 线索跟进记录Controller
 *
 * @date 2021-04-22
 */
@RestController
@RequestMapping("/clues/record")
public class TbClueTrackRecordController extends BaseController {
    @Autowired
    ITbClueTrackRecordService itbClueTrackRecordService;

    @GetMapping("/list")
    public AjaxResult getClueTrackRecord(@RequestParam("clueId") Long id){

        TbClueTrackRecord tbClueTrackRecord = itbClueTrackRecordService.selectTbClueTrackRecordById(id);

        return AjaxResult.success(tbClueTrackRecord);

    }



    @PostMapping
    public AjaxResult addClueTrackRecord(@RequestBody ClueTrackRecordVo clueTrackRecordVo) {
        TbClueTrackRecord tbClueTrackRecord  = new TbClueTrackRecord();
        BeanUtils.copyProperties(clueTrackRecordVo, tbClueTrackRecord);
        tbClueTrackRecord.setCreateBy(SecurityUtils.getUsername());
        tbClueTrackRecord.setCreateTime(new Date());
        TbClue tbClue=new TbClue();
        BeanUtils.copyProperties(tbClueTrackRecord,tbClue);
        tbClue.setStatus(TbClue.StatusType.FOLLOWING.getValue()); //进行中
        tbClue.setId(tbClueTrackRecord.getClueId());

        return toAjax(itbClueTrackRecordService.addClueTrackRecord(tbClueTrackRecord));
    }

}